"""
Case Type   : 系统内部使用工具
Case Name   : gs_ctl：指定参数--show,显示内部设置
Create At   : 2022-07-28
Owner       : liu-tong-8848
Description :
    1.执行gs_ctl init的命令
Expect      :
    1.成功
History     :
"""

import unittest
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro
import os


class Tools(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.userNode = Node('PrimaryDbUser')
        self.DB_ENV_PATH = macro.DB_ENV_PATH
        self.dir_path = os.path.join(macro.DB_INSTANCE_PATH, 'datadir')
        self.nodename = 'nodename_146'

    def test_systools(self):
        self.logger.info(f'-----{os.path.basename(__file__)}' + ' start-----')

        text = '--step1:执行gs_ctl init的命令；expect：成功--'
        self.logger.info(text)
        excute_cmd1 = f'source {self.DB_ENV_PATH};' \
                      f'gs_ctl init -D {self.dir_path} -o ' \
                      f'"--nodename="{self.nodename}" -w ' \
                      f'"{self.userNode.ssh_password}" --show "'
        self.logger.info(excute_cmd1)
        msg1 = self.userNode.sh(excute_cmd1).result()
        self.logger.info(msg1)
        msg_list = ['VERSION', 'PGDATA', 'share_path', 'PGPATH',
                    'POSTGRES_SUPERUSERNAME', 'POSTGRES_BKI',
                    'POSTGRES_DESCR', 'POSTGRES_SHDESCR',
                    'POSTGRESQL_CONF_SAMPLE', 'MOT_CONF_SAMPLE',
                    'PG_HBA_SAMPLE', 'PG_IDENT_SAMPLE']
        for content in msg_list:
            self.assertTrue(content in msg1, text + '执行失败')

    def tearDown(self):
        self.logger.info(
            f'-----{os.path.basename(__file__)}' + ' end-----')
